home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / coding / 80x86 / code32.lzh / EXAMPLE4.ASM < prev    next >
Assembly Source File  |  1993-01-09  |  6KB  |  194 lines

  1.  
  2. ; A simple program that loads a file, dumps it to screen, and lets you move
  3. ; around in it using the arrow keys. ESC quits. It loads the file into
  4. ; extended memory, if for no other reason that to demonstrate its use.
  5. ; This program makes use of a switch with a numeric string associated.
  6. ;
  7. ; Link this with FILE32, KB32, and ARGC32, and enable OPENFILE, READFILE,
  8. ; FILESIZE, CCHEKSTR, and CCHEKSWITCH in their respective libs.
  9.  
  10.         .386p
  11.         jumps
  12. code32  segment para public use32
  13.         assume cs:code32, ds:code32, ss:code32
  14.  
  15. include start32.inc
  16. include file32.inc
  17. include argc32.inc
  18. include kb32.inc
  19.  
  20. public  _main
  21.  
  22. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  23. ; DATA
  24. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  25. errmsg0         db      'SYNTAX: EXAMPLE4 [-a#] <filename>',0dh,0ah,0dh,0ah
  26.                 db      '  The -a switch changes the screen attributes for '
  27.                 db      'displaying the file.',0dh,0ah,'$'
  28. errmsg1         db      'Error opening input file!!!$'
  29. errmsg2         db      'Not enough extended memory to load file!!!$'
  30.  
  31. fnm             db      64 dup(?)
  32.  
  33. keytbl          db      7,  23,24,25,26, 19,20, 14
  34. functbl         dd      func0,func1,func2,func3,func4,func5,_exit
  35.  
  36. dataptr         dd      ?               ; ptr to beginning of data
  37. datalen         dd      ?               ; length of file
  38. dataloc         dd      0               ; location in data to display
  39. dispattr        db      7               ; display attribute
  40.  
  41. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  42. ; CODE
  43. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  44.  
  45. include strltu.rt
  46. include strhtn.rt
  47. include indxbyte.rt
  48.  
  49. ;-----------------------------------------------------------------------------
  50. exiterr2:
  51.         mov edx,offset errmsg2
  52.         jmp short exiterr
  53. ;-----------------------------------------------------------------------------
  54. exiterr1:
  55.         mov edx,offset errmsg1
  56.         jmp short exiterr
  57. ;-----------------------------------------------------------------------------
  58. exiterr0:
  59.         mov edx,offset errmsg0
  60. exiterr:
  61.         call _putdosmsg
  62.         jmp _exit
  63.  
  64. ;═════════════════════════════════════════════════════════════════════════════
  65. _main:
  66.         mov al,'a'                      ; chek for attribute switch
  67.         call _cchekswitch
  68.         jc short mf0
  69.  
  70.         mov edx,_lomembase              ; misc data ptr
  71.         call _ccheksstr
  72.         call _strltu                    ; convert string to number
  73.         call _strhtn
  74.         mov dispattr,al
  75.  
  76. mf0:
  77.         xor al,al                       ; chek for filename on commandline
  78.         mov edx,offset fnm
  79.         call _cchekstr
  80.         jc exiterr0
  81.  
  82.         call _openfile                  ; attempt to open file
  83.         jc exiterr1
  84.  
  85.         mov eax,4000h                   ; setup file buffer
  86.         call _getlomem
  87.         mov _filebufloc,eax
  88.  
  89.         call _filesize                  ; get size and make it a min of 80*25
  90.         push eax                        ; store for later use
  91.         cmp eax,80*25
  92.         jae short mf1
  93.         mov eax,80*25
  94. mf1:
  95.         mov datalen,eax
  96.  
  97.         call _gethimem                  ; chek for, and get enough himem
  98.         jc exiterr2
  99.         mov dataptr,eax
  100.         mov edi,eax                     ; fill 80*25 bytes with blanks
  101.         mov ecx,(80*25)/4
  102.         mov eax,20202020h
  103.         rep stosd
  104.  
  105.         mov edx,dataptr                 ; load file into himem
  106.         pop ecx                         ; restore actual filesize for load
  107.         call _readfile
  108.         call _closefile
  109.  
  110.         call _init_kb                   ; initialize keyboard
  111.  
  112. ;═════════════════════════════════════════════════════════════════════════════
  113. mainloop:
  114.         mov esi,dataptr                 ; put this page of data
  115.         add esi,dataloc
  116.         call disppage
  117.  
  118. mlf0:
  119.         call _getch                     ; get key
  120.  
  121.         mov edx,offset keytbl           ; index key in table
  122.         call _indexbyte
  123.         jc mlf0
  124.  
  125.         call functbl[eax*4]             ; call function for key
  126.         jmp mainloop
  127.  
  128. ;─────────────────────────────────────────────────────────────────────────────
  129. func0:                                  ; left arrow key
  130.         sub dataloc,1
  131.         adc dataloc,0
  132.         ret
  133. ;─────────────────────────────────────────────────────────────────────────────
  134. func1:                                  ; right arrow key
  135.         mov eax,dataloc
  136.         inc eax
  137.         lea ebx,[eax+80*25]
  138.         cmp ebx,datalen
  139.         ja _ret
  140.         mov dataloc,eax
  141.         ret
  142. ;─────────────────────────────────────────────────────────────────────────────
  143. func2:                                  ; up arrow key
  144.         mov eax,dataloc
  145.         sub eax,80
  146.         jc _ret
  147.         mov dataloc,eax
  148.         ret
  149. ;─────────────────────────────────────────────────────────────────────────────
  150. func3:                                  ; down arrow key
  151.         mov eax,dataloc
  152.         add eax,80
  153.         lea ebx,[eax+80*25]
  154.         cmp ebx,datalen
  155.         ja _ret
  156.         mov dataloc,eax
  157.         ret
  158. ;─────────────────────────────────────────────────────────────────────────────
  159. func4:                                  ; home key
  160.         mov dataloc,0
  161.         ret
  162. ;─────────────────────────────────────────────────────────────────────────────
  163. func5:                                  ; end key
  164.         mov eax,datalen
  165.         sub eax,80*25
  166.         mov dataloc,eax
  167.         ret
  168.  
  169. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  170. ; Display one screen of the file
  171. ; In:
  172. ;   ESI -> memory area to display from
  173. ; Out:
  174. ;   None
  175. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  176. disppage:
  177.         push ax ecx esi edi
  178.  
  179.         @rlp edi,0b8000h
  180.         mov ecx,80*25
  181.         mov al,dispattr
  182. disppageml:
  183.         movsb
  184.         stosb
  185.         loop disppageml
  186.  
  187.         pop edi esi ecx ax
  188.         ret
  189.  
  190.  
  191. code32  ends
  192.         end
  193.  
  194.